package com.gitee.gateway.core.common;

import com.gitee.gateway.core.db.DatabaseManager;
import io.vertx.codegen.annotations.GenIgnore;
import org.jdbi.v3.core.extension.ExtensionCallback;
import org.jdbi.v3.core.extension.ExtensionConsumer;

@GenIgnore
public interface ServiceBase {

    default <E, X extends Exception> void USE(Class<E> extensionType, ExtensionConsumer<E, X> callback) throws X {
        DatabaseManager.useExtension(extensionType, callback);
    }

    default <R, E, X extends Exception> R WITH(Class<E> extensionType, ExtensionCallback<R, E, X> callback) throws X {
        return DatabaseManager.withExtension(extensionType, callback);
    }

    default <E> E USE(Class<E> daoClass) {
        return DatabaseManager.onDemand(daoClass);
    }

}
